<?php
include("../common.inc.php");
InitGP(array("page","action","aid","delids")); //初始化变量全局返回
include("function_common.php");
//初始化对象
include(INC_PATH."/article.class.php");
$art=new ArticleClass();


if(empty($action)){
	InitGP(array("typeid","title")); //初始化变量全局返回
	$wheresql="";
	$wherestr=array();
	if(!empty($typeid))$wherestr[]="typeid='{$typeid}'";
	if(!empty($title))$wherestr[]="title like '%{$title}%'";
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//条件汇总
	
	//获取当前页码
	$total=$art->getcount($wheresql); 							  //总信息数
	$pagesize=15;												  //一页显示信息数
	$page = isset($page) ? max(1, intval($page)) : 1;             //处理页码变量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$art->getdata("$offset,$pagesize",$wheresql); //获取团购数据
	
	//包含后台模板文件
	include("tpl/article_list.htm");
}elseif ($action=="edit") {
	InitGP(array("aid","imgold","title","typeid","linkurl","order","seokeywords","seodescription","body","Submit")); //初始化变量全局返回
	if(!empty($Submit)){
		//处理提交动作
		if(isset($aid) && isset($title)){
		//处理数据
		//上传图片处理
		require_once (INC_PATH.'/upload.class.php');
		$f = new Upload();
		$f->setThumb(0);//设置不生成缩微图
		$f->run('fileimg',1);
		$info=$f->getInfo();
		$imgdata=$info[0]['fullsavename'];//获取第一个上传图片反馈
		if(isset($info[0]['error']))$imgdata=$imgold;
		//处理数据
		$arrayedit=array(
			"title"=> Char_cv($title),
			"typeid"=> GetNum($typeid),
			"litpic"=> $imgdata ,
			"linkurl"=> Char_cv($linkurl),
			"order"=>GetNum($order) ,
			"seokeywords"=> Char_cv($seokeywords),
			"seodescription"=> Char_cv($seodescription),
			"body"=>HtmlReplace($body,-1)
		);
		//执行编辑操作
		$info=$art->edit($aid,$arrayedit);
		if($info=="OK"){
			showmsg("编辑文章成功!","article_list.php");//成功
		}else showmsg($info,"article_add.php");//出错！
	}else showmsg("缺少参数","article_add.php");//出错！
		
	}else {
	
	//编辑信息表单
	$dataedit=$art->getdata(1,"aid={$aid}");
	$value=$dataedit[0];//获取第一条记录
	$selectstr=$art->getselect("typeid",$value['typeid']); //获取分类数据
	//包含后台模板文件
	include("tpl/article_edit.htm");	
	}
}elseif ($action=="del" && !empty($aid)){
	//执行删除操作
	$aid=GetNum($aid);
	$info=$art->del($aid);
	if($info=="OK")showmsg("删除文章成功！","article_list.php");
	else showmsg($info,"article_list.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("没有选择任何对象！","article_list.php");exit;}//空选择
	//执行删除多个操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$art->del($id);
	}
	if($info=="OK")showmsg("删除文章成功！","article_list.php");
	else showmsg($info,"article_list.php");
}


?>

